<template>
  <div class="success-container">
    <!-- 品牌装饰背景 -->
    <div class="brand-decoration"></div>

    <!-- 成功动画区域 -->
    <div class="success-animation-area">
      <div class="celebration-particles">
        <div class="particle" v-for="n in 15" :key="n" :style="getParticleStyle(n)"></div>
      </div>

      <div class="success-icon-container">
        <div class="success-icon">
          <div class="check-mark">✓</div>
        </div>
        <div class="success-rings">
          <div class="ring ring-1"></div>
          <div class="ring ring-2"></div>
          <div class="ring ring-3"></div>
        </div>
      </div>
    </div>

    <!-- 页面头部 -->
    <div class="header">
      <div class="brand-logo">
      </div>
      <h1>Payment Successful!</h1>
      <p>Thank you for your kindness and generosity</p>
    </div>

    <!-- 成功状态卡片 -->
    <div class="success-card fade-in">
      <div class="success-header">
        <div class="success-badge">✨ Completed</div>
        <h2 class="success-title">Your payment was successful!</h2>

      </div>
    </div>

    <!-- 朋友通知卡片 -->
    <div class="notification-card fade-in" style="animation-delay: 0.2s;">
      <div class="notification-header">
        <div class="notification-icon">📱</div>
        <h3>Friend Notified</h3>
      </div>
      <div class="notification-content">
        <div class="notification-item">
          <div class="notification-step">
            <div class="step-icon completed">✓</div>
            <div class="step-text">
              <div class="step-title">has been notified</div>
              <div class="step-desc">Your friend received a notification about the order</div>
            </div>
          </div>
        </div>
        <div class="notification-item">
          <div class="notification-step">
            <div class="step-icon processing">🍳</div>
            <div class="step-text">
              <div class="step-title">Restaurant is preparing</div>
              <div class="step-desc">Expected delivery in 35-45 minutes</div>
            </div>
          </div>
        </div>
        <div class="notification-item">
          <div class="notification-step">
            <div class="step-icon pending">🚚</div>
            <div class="step-text">
              <div class="step-title">Delivery in progress</div>
              <div class="step-desc">Real-time tracking available</div>
            </div>
          </div>
        </div>
      </div>
    </div>


    <!-- 安全保障卡片 -->
    <div class="security-card fade-in" style="animation-delay: 0.6s;">
      <div class="security-header">
        <div class="security-icon">🛡️</div>
        <h3>Your Payment is Secure</h3>
      </div>
      <div class="security-content">
        <div class="security-features">
          <div class="security-item">
            <span class="security-check">✓</span>
            <span>End-to-end encryption</span>
          </div>
          <div class="security-item">
            <span class="security-check">✓</span>
            <span>PayPal buyer protection</span>
          </div>
          <div class="security-item">
            <span class="security-check">✓</span>
            <span>Secure transaction processing</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部感谢信息 -->
    <div class="gratitude-section fade-in" style="animation-delay: 0.8s;">
      <div class="gratitude-content">
        <div class="gratitude-icon">❤️</div>
        <h3>Thank You for Spreading Joy!</h3>
        <p>Your thoughtful gesture makes the world a little brighter. </p>
      </div>
    </div>

    <!-- 底部装饰 -->
    <div class="bottom-decoration">
      <div class="decoration-text">COKFOOD - Connecting Friends Through Food</div>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

// 从路由参数或查询参数获取数据
const friendName = ref(route.query.friendName as string || 'Your Friend')
const totalAmount = ref(route.query.amount as string || '25.99')
const orderNo = ref(route.query.orderNo as string || '')

// 粒子动画样式生成
const getParticleStyle = (index: number) => {
  const colors = ['#EF4444', '#10B981', '#F59E0B', '#8B5CF6', '#06B6D4']
  const randomColor = colors[index % colors.length]
  const randomDelay = Math.random() * 2
  const randomDuration = 2 + Math.random() * 2
  const randomX = Math.random() * 100
  const randomY = Math.random() * 100

  return {
    backgroundColor: randomColor,
    left: `${randomX}%`,
    top: `${randomY}%`,
    animationDelay: `${randomDelay}s`,
    animationDuration: `${randomDuration}s`
  }
}

const viewOrderDetails = () => {
  if (orderNo.value) {
    router.push(`/order/${orderNo.value}`)
  } else {
    router.push('/orders')
  }
}

const continueShopping = () => {
  router.push('/')
}

const shareSuccess = () => {
  if (navigator.share) {
    navigator.share({
      title: 'I just helped a friend order food!',
      text: `I helped ${friendName.value} order delicious food through COKFOOD. Spreading kindness one meal at a time! 🍽️❤️`,
      url: window.location.origin
    })
  } else {
    // 复制链接到剪贴板
    const shareText = `I helped ${friendName.value} order delicious food through COKFOOD. Spreading kindness one meal at a time! 🍽️❤️`
    navigator.clipboard.writeText(shareText)
    console.log('Share text copied to clipboard')
  }
}

onMounted(() => {
  // 触发庆祝动画
  setTimeout(() => {
    document.querySelector('.success-icon')?.classList.add('animate')
  }, 500)
})
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.success-container {
  max-width: 430px;
  margin: 0 auto;
  background-color: #FFFFFF;
  min-height: 100vh;
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
  overflow-x: hidden;
}

/* 品牌装饰背景 */
.brand-decoration {
  position: absolute;
  width: 100%;
  height: 350px;
  top: 0;
  left: 0;
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  overflow: hidden;
  z-index: 0;
}

.brand-decoration::before {
  content: '';
  position: absolute;
  width: 150%;
  height: 150%;
  top: -50%;
  right: -50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 50%);
  animation: float 25s ease-in-out infinite;
}

.brand-decoration::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  width: 100%;
  height: 100px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%23FFFFFF' fill-opacity='1' d='M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,112C672,96,768,96,864,112C960,128,1056,160,1152,160C1248,160,1344,128,1392,112L1440,96L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E") no-repeat bottom;
  background-size: cover;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-30px) rotate(180deg); }
}

/* 成功动画区域 */
.success-animation-area {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
}

.celebration-particles {
  position: absolute;
  width: 300px;
  height: 300px;
  top: -100px;
  left: -150px;
  pointer-events: none;
}

.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: particleFly 4s ease-out infinite;
}

@keyframes particleFly {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(-200px) translateX(var(--random-x, 50px)) rotate(360deg);
    opacity: 0;
  }
}

.success-icon-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.success-icon {
  width: 120px;
  height: 120px;
  background: linear-gradient(135deg, #10B981, #059669);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 20px 60px rgba(16, 185, 129, 0.4);
  position: relative;
  animation: successPulse 2s ease-in-out infinite;
}

.success-icon.animate {
  animation: successBounce 0.6s ease-out;
}

@keyframes successPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes successBounce {
  0% { transform: scale(0); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.check-mark {
  font-size: 60px;
  color: white;
  font-weight: bold;
  animation: checkmarkDraw 0.8s ease-out 0.3s both;
}

@keyframes checkmarkDraw {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

.success-rings {
  position: absolute;
}

.ring {
  position: absolute;
  border: 3px solid rgba(16, 185, 129, 0.3);
  border-radius: 50%;
  animation: ringExpand 2s ease-out infinite;
}

.ring-1 {
  width: 140px;
  height: 140px;
  top: -10px;
  left: -10px;
}

.ring-2 {
  width: 180px;
  height: 180px;
  top: -30px;
  left: -30px;
  animation-delay: 0.3s;
}

.ring-3 {
  width: 220px;
  height: 220px;
  top: -50px;
  left: -50px;
  animation-delay: 0.6s;
}

@keyframes ringExpand {
  0% {
    transform: scale(0.8);
    opacity: 1;
  }
  100% {
    transform: scale(1.2);
    opacity: 0;
  }
}

/* 页面头部 */
.header {
  position: relative;
  padding: 180px 20px 80px;
  text-align: center;
  color: white;
  z-index: 1;
}

.brand-logo {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 20px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.brand-logo span {
  background: linear-gradient(45deg, #FFFFFF 30%, #F0FDF4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 10px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header p {
  font-size: 16px;
  opacity: 0.95;
  font-weight: 300;
}

/* 成功状态卡片 */
.success-card {
  margin: -40px 20px 30px;
  padding: 30px;
  background: linear-gradient(135deg, #F0FDF4 0%, #ECFDF5 100%);
  border-radius: 20px;
  box-shadow: 0 8px 30px rgba(16, 185, 129, 0.15);
  position: relative;
  overflow: hidden;
  z-index: 2;
  border: 1px solid rgba(16, 185, 129, 0.1);
}

.success-badge {
  display: inline-block;
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 15px;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.success-title {
  font-size: 24px;
  font-weight: 700;
  color: #1F2937;
  margin-bottom: 10px;
}

.success-message {
  font-size: 16px;
  color: #6B7280;
  line-height: 1.6;
  margin-bottom: 25px;
}

.payment-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  border: 1px solid rgba(16, 185, 129, 0.1);
}

.amount-paid {
  text-align: left;
}

.amount-label {
  font-size: 14px;
  color: #6B7280;
  margin-bottom: 5px;
}

.amount-value {
  font-size: 24px;
  font-weight: 800;
  background: linear-gradient(135deg, #10B981, #059669);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.payment-method {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  color: #374151;
  font-weight: 500;
}

.method-icon {
  font-size: 20px;
}

/* 朋友通知卡片 */
.notification-card {
  margin: 0 20px 30px;
  padding: 25px;
  background: #FFFFFF;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #F3F4F6;
}

.notification-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.notification-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3B82F6, #1D4ED8);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.notification-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #1F2937;
}

.notification-item {
  margin-bottom: 16px;
}

.notification-step {
  display: flex;
  align-items: flex-start;
  gap: 15px;
}

.step-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.step-icon.completed {
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
}

.step-icon.processing {
  background: linear-gradient(135deg, #F59E0B, #D97706);
  color: white;
  animation: processing 2s ease-in-out infinite;
}

.step-icon.pending {
  background: #F3F4F6;
  color: #6B7280;
}

@keyframes processing {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.step-text {
  flex: 1;
}

.step-title {
  font-size: 16px;
  font-weight: 600;
  color: #1F2937;
  margin-bottom: 4px;
}

.step-desc {
  font-size: 14px;
  color: #6B7280;
}

/* 操作按钮区域 */
.actions-section {
  margin: 0 20px 30px;
}

.primary-action-btn,
.secondary-action-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 18px 20px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-bottom: 12px;
  text-align: left;
}

.primary-action-btn {
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  color: white;
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.3);
}

.primary-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 35px rgba(16, 185, 129, 0.4);
}

.secondary-action-btn {
  background: linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%);
  color: #1F2937;
  border: 1px solid #D1D5DB;
}

.secondary-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
  background: linear-gradient(135deg, #E5E7EB 0%, #D1D5DB 100%);
}

.btn-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.secondary-action-btn .btn-icon {
  background: rgba(16, 185, 129, 0.1);
}

.btn-content {
  flex: 1;
}

.btn-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}

.btn-subtitle {
  font-size: 13px;
  opacity: 0.8;
}

.btn-arrow {
  font-size: 18px;
  font-weight: 600;
  opacity: 0.7;
  transition: transform 0.3s ease;
}

.primary-action-btn:hover .btn-arrow,
.secondary-action-btn:hover .btn-arrow {
  transform: translateX(5px);
}

.share-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 20px;
  background: linear-gradient(135deg, #8B5CF6, #7C3AED);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 8px;
}

.share-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(139, 92, 246, 0.3);
}

/* 安全保障卡片 */
.security-card {
  margin: 0 20px 30px;
  padding: 25px;
  background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid #FDE68A;
}

.security-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.security-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #F59E0B, #D97706);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.security-header h3 {
  font-size: 18px;
  font-weight: 600;
  color: #1F2937;
}

.security-features {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.security-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #374151;
}

.security-check {
  color: #10B981;
  font-weight: 600;
  font-size: 16px;
}

/* 感谢区域 */
.gratitude-section {
  margin: 0 20px 30px;
  padding: 30px;
  background: linear-gradient(135deg, #FDF2F8 0%, #FCE7F3 100%);
  border-radius: 20px;
  text-align: center;
  border: 1px solid #F9A8D4;
}

.gratitude-icon {
  font-size: 50px;
  margin-bottom: 15px;
  animation: heartbeat 2s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.gratitude-section h3 {
  font-size: 20px;
  font-weight: 700;
  color: #1F2937;
  margin-bottom: 10px;
}

.gratitude-section p {
  font-size: 16px;
  color: #6B7280;
  line-height: 1.6;
}

/* 底部装饰 */
.bottom-decoration {
  text-align: center;
  padding: 30px 20px;
  color: #9CA3AF;
}

.decoration-text {
  font-size: 14px;
  font-weight: 500;
}

/* 动画效果 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeInUp 0.6s ease-out;
  animation-fill-mode: both;
}

/* 响应式设计 */
@media (max-width: 430px) {
  .success-container {
    box-shadow: none;
  }

  .success-card,
  .notification-card,
  .actions-section,
  .security-card,
  .gratitude-section {
    margin-left: 16px;
    margin-right: 16px;
  }
}
</style>
